package cn.wolfcode.luowowo.mgrsite.controller;

import cn.wolfcode.luowowo.article.domain.StrategyDetail;
import cn.wolfcode.luowowo.article.service.IStrategTagService;
import cn.wolfcode.luowowo.article.service.IStrategyCatalogService;
import cn.wolfcode.luowowo.article.service.IStrategyDetailService;
import cn.wolfcode.luowowo.article.service.IStrategyThemeService;
import cn.wolfcode.luowowo.common.query.QueryObject;
import cn.wolfcode.luowowo.common.util.AjaxResult;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.time.chrono.IsoChronology;

@Controller
@RequestMapping("strategyDetail")
public class StrategDetailController {
    @Reference
    private IStrategyDetailService strategyDetailService;

    @Reference
    private IStrategyCatalogService strategyCatalogService;
    @Reference
    private IStrategyThemeService strategyThemeService;

    @RequestMapping("list")
   public String list(@ModelAttribute("qo")QueryObject qo,Model model){
        PageInfo<StrategyDetail> pageInfo = strategyDetailService.queryForList(qo);
        model.addAttribute("pageInfo",pageInfo);
        return "strategyDetail/list";
    }

    @RequestMapping("input")
    public String input(Long id,Model model){

        if(id!=null){
            model.addAttribute("entity",strategyDetailService.selectByPrimaryKey(id));
            //共享改文章的标签
            model.addAttribute("tags",strategyDetailService.getTags(id));
        }
        model.addAttribute("catalogs",strategyCatalogService.selectAll());
        model.addAttribute("themes",strategyThemeService.selectAll());
        return "strategyDetail/input";
    }
    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(StrategyDetail strategyDetail,String tags){
        strategyDetailService.saveOrUpdate(strategyDetail,tags);
        return new AjaxResult();
    }
}
